package com.toro.config;

import com.toro.protocol.Serializer;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @ClassName: Config
 * @Description:
 * @Author: ToroLHZ
 * @Date: 2023/12/11 17:13
 */
public abstract class Config {
    static Properties properties;

    static {
        try (InputStream in = Config.class.getResourceAsStream("/application.properties")) {
            properties = new Properties();
            properties.load(in);
        } catch (IOException e) {
            throw new ExceptionInInitializerError(e);
        }
    }

    public static int getServerPort() {
        String value = properties.getProperty("server.port");
        if (value == null) {
            return 8080;
        } else {
            return Integer.parseInt(value);
        }
    }

    public static String getClientIP(){
        String value = properties.getProperty("client.IP");
        if(value==null)
        {
            return "localhost";
        }else {
            return value;
        }
    }

    public static int getClientPort(){
        String value = properties.getProperty("client.port");
        if (value == null) {
            return 8080;
        } else {
            return Integer.parseInt(value);
        }
    }

    public static int getHeartListener(){
        String value = properties.getProperty("server.listenerHeart");
        if (value == null) {
            return 600;
        } else {
            return Integer.parseInt(value);
        }
    }
    public static int getHeartSend(){
        String value = properties.getProperty("client.sendHeart");
        if (value == null) {
            return 300;
        } else {
            return Integer.parseInt(value);
        }
    }

    public static Serializer.Algorithm getSerializerAlgorithm() {
        String value = properties.getProperty("serializer.algorithm");
        if (value == null) {
            return Serializer.Algorithm.Java;
        } else {
            return Serializer.Algorithm.valueOf(value);
        }
    }
}
